/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FormCetakStruk.java
 *
 * Created on 06 Des 11, 0:39:15
 */
package Boundaries;

import Controller.Registration_Controller;
import Entities.Kendaraan;
import Entities.Sewa;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;


/**
 *
 * @author Tea-Nose
 */
public class FormCetakStruk extends javax.swing.JDialog {
    Sewa sewa2;
    Kendaraan kend2;
    Registration_Controller reg_C2;
    InternalFrame_Persewaan in_Sewa;
    /** Creates new form FormCetakStruk */
    public FormCetakStruk(javax.swing.JInternalFrame frame, boolean modal, Sewa sewa, Kendaraan kendaraan, Registration_Controller reg_C, InternalFrame_Persewaan x) {
        sewa2=sewa;
        kend2=kendaraan;
        reg_C2=reg_C;
        in_Sewa=x;
        
        try {
            //        super(parent, modal);
            initComponents();
            Date date = new Date();
            label_dateSewa.setText(date.toLocaleString());
            InternalFrame_Persewaan formReg = (InternalFrame_Persewaan) frame;
            label_NoFaktur.setText(formReg.tf_Sewa_noFaktur.getText());
            label_Karyawan.setText(formReg.label_Sewa_NilaiUserName.getText());
            label_NilaiNamaPenyewa.setText(formReg.tf_Sewa_namaPenyewa.getText());
            label_NilaiAlamatPenyewa.setText(formReg.ta_Sewa_AlamatPenyewa.getText());
            label_NilaiNoTelpPenyewa.setText(formReg.tf_Sewa_TelpPenyewa.getText());
            label_NilaiTglSewa.setText(formReg.dateChosser_Sewa_TanggalSewa.getDate().toLocaleString());
            label_NilaiTglKemb.setText(formReg.dateChosser_Sewa_TanggalKembali2.getDate().toLocaleString());
            label_NilaiUangSewa.setText(formReg.tf_Sewa_UangSewa.getText());
            Kendaraan kend = new Kendaraan();
            kend.getDataKendaraanBasedOnNoPolisi(formReg.tf_Sewa_noPolisiKendaraan.getText());
            label_NilaiMerkMobil.setText(kend.getMerk_kendaraan());
            label_NilaiNoPolisi.setText(kend.getNo_polisi());
            label_NilaiSpesifiaksiKend.setText(kend.getSpesifikasi_kendaraan());
            label_NilaiTipeKend.setText(kend.getTipe_kendaraan());
            label_NilaiWarnaKend.setText(kend.getWarna_kendaraan());
        } catch (SQLException ex) {
            Logger.getLogger(FormCetakStruk.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSeparator1 = new javax.swing.JSeparator();
        label_TitleCorp = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        label_Karyawan = new javax.swing.JLabel();
        label_NilaiUangSewa = new javax.swing.JLabel();
        label_NilaiNamaPenyewa = new javax.swing.JLabel();
        label_NilaiAlamatPenyewa = new javax.swing.JLabel();
        label_NilaiNoTelpPenyewa = new javax.swing.JLabel();
        label_NilaiMerkMobil = new javax.swing.JLabel();
        label_NilaiNoPolisi = new javax.swing.JLabel();
        label_NoFaktur = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        label_NilaiTipeKend = new javax.swing.JLabel();
        label_NilaiWarnaKend = new javax.swing.JLabel();
        jSeparator3 = new javax.swing.JSeparator();
        label_NilaiSpesifiaksiKend = new javax.swing.JLabel();
        label_NilaiTglSewa = new javax.swing.JLabel();
        label_NilaiTglKemb = new javax.swing.JLabel();
        label_namaPenyewa = new javax.swing.JLabel();
        label_AlamatPenyewa = new javax.swing.JLabel();
        label_NoTelpPenyewa = new javax.swing.JLabel();
        label_MerkMobil = new javax.swing.JLabel();
        label_NoPolisi = new javax.swing.JLabel();
        label_TipeKendaraan = new javax.swing.JLabel();
        label_WarnaKendaraan = new javax.swing.JLabel();
        label_SpesifikasiKendaraan = new javax.swing.JLabel();
        label_TanggalSewa = new javax.swing.JLabel();
        label_TanggalKembali = new javax.swing.JLabel();
        label_UangSewa = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        label_dateSewa = new javax.swing.JLabel();
        cetakButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
        getContentPane().add(jSeparator1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 70, 490, -1));

        label_TitleCorp.setFont(new java.awt.Font("Tahoma", 1, 12));
        label_TitleCorp.setText("Rental Mobil 1 Milyar");
        getContentPane().add(label_TitleCorp, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, -1, -1));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24));
        jLabel1.setText("Nota Bukti Sewa");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 20, 200, 40));

        label_Karyawan.setText("jLabel2");
        getContentPane().add(label_Karyawan, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 80, -1, -1));

        label_NilaiUangSewa.setText("Uang Sewa");
        getContentPane().add(label_NilaiUangSewa, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 360, -1, -1));

        label_NilaiNamaPenyewa.setText("Nama Penyewa");
        getContentPane().add(label_NilaiNamaPenyewa, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 120, -1, -1));

        label_NilaiAlamatPenyewa.setText("Alamat Penyewa");
        getContentPane().add(label_NilaiAlamatPenyewa, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 140, -1, -1));

        label_NilaiNoTelpPenyewa.setText("No. Telp Penyewa");
        getContentPane().add(label_NilaiNoTelpPenyewa, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 160, -1, -1));

        label_NilaiMerkMobil.setText("Merk Mobil");
        getContentPane().add(label_NilaiMerkMobil, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 200, -1, -1));

        label_NilaiNoPolisi.setText("No Polisi ");
        getContentPane().add(label_NilaiNoPolisi, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 220, -1, -1));

        label_NoFaktur.setFont(new java.awt.Font("Tahoma", 1, 12));
        label_NoFaktur.setText("jLabel8");
        label_NoFaktur.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2));
        getContentPane().add(label_NoFaktur, new org.netbeans.lib.awtextra.AbsoluteConstraints(418, 10, 60, 20));
        getContentPane().add(jSeparator2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 190, 470, -1));

        label_NilaiTipeKend.setText("Tipe Kendaraan");
        getContentPane().add(label_NilaiTipeKend, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 240, -1, -1));

        label_NilaiWarnaKend.setText("Warna Kendaraan");
        getContentPane().add(label_NilaiWarnaKend, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 260, -1, -1));
        getContentPane().add(jSeparator3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 310, 470, 10));

        label_NilaiSpesifiaksiKend.setText("Spesifiaksi Kendaraan");
        getContentPane().add(label_NilaiSpesifiaksiKend, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 280, -1, -1));

        label_NilaiTglSewa.setText("Tanggal Sewa");
        getContentPane().add(label_NilaiTglSewa, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 320, -1, -1));

        label_NilaiTglKemb.setText("Tanggal Kembali");
        getContentPane().add(label_NilaiTglKemb, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 340, -1, -1));

        label_namaPenyewa.setText("Nama Penyewa");
        getContentPane().add(label_namaPenyewa, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 120, -1, -1));

        label_AlamatPenyewa.setText("Alamat Penyewa");
        getContentPane().add(label_AlamatPenyewa, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 140, -1, -1));

        label_NoTelpPenyewa.setText("No. Telp Penyewa");
        getContentPane().add(label_NoTelpPenyewa, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 160, -1, -1));

        label_MerkMobil.setText("Merk Mobil");
        getContentPane().add(label_MerkMobil, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 200, -1, -1));

        label_NoPolisi.setText("No Polisi ");
        getContentPane().add(label_NoPolisi, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 220, -1, -1));

        label_TipeKendaraan.setText("Tipe Kendaraan");
        getContentPane().add(label_TipeKendaraan, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 240, -1, -1));

        label_WarnaKendaraan.setText("Warna Kendaraan");
        getContentPane().add(label_WarnaKendaraan, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 260, -1, -1));

        label_SpesifikasiKendaraan.setText("Spesifiaksi Kendaraan");
        getContentPane().add(label_SpesifikasiKendaraan, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 280, -1, -1));

        label_TanggalSewa.setText("Tanggal Sewa");
        getContentPane().add(label_TanggalSewa, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 320, -1, -1));

        label_TanggalKembali.setText("Tanggal Kembali");
        getContentPane().add(label_TanggalKembali, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 340, -1, -1));

        label_UangSewa.setText("Uang Sewa");
        getContentPane().add(label_UangSewa, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 360, -1, -1));

        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        label_dateSewa.setText("jLabel2");
        jPanel1.add(label_dateSewa, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 80, 120, -1));

        cetakButton.setText("Print");
        cetakButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cetakButtonActionPerformed(evt);
            }
        });
        jPanel1.add(cetakButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 400, 90, -1));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 490, 440));

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-506)/2, (screenSize.height-478)/2, 506, 478);
    }// </editor-fold>//GEN-END:initComponents

    private void cetakButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cetakButtonActionPerformed
        // TODO add your handling code here:
        try {
            sewa2.insertSewa();
            try {
                sewa2.fakturSewa();
            } catch (SQLException ex) {
                Logger.getLogger(FormCetakStruk.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                kend2.changeStatusKendaraanToSewa(in_Sewa.tf_Sewa_noPolisiKendaraan.getText());
            } catch (SQLException ex) {
                Logger.getLogger(FormCetakStruk.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                in_Sewa.tf_Sewa_noFaktur.setText(sewa2.fakturSewa());
            } catch (SQLException ex) {
                Logger.getLogger(FormCetakStruk.class.getName()).log(Level.SEVERE, null, ex);
            }
           in_Sewa.tf_Sewa_namaPenyewa.setText("");
            in_Sewa.tf_Sewa_TelpPenyewa.setText("");
            in_Sewa.ta_Sewa_AlamatPenyewa.setText("");
            in_Sewa.tf_Sewa_noPolisiKendaraan.setText("");
            in_Sewa.tf_Sewa_statusKendaraan.setText("");
            in_Sewa.tf_Sewa_statusKendaraan.setEnabled(false);
            in_Sewa.dateChosser_Sewa_TanggalSewa.setEnabled(false);
            in_Sewa.jTable1.setVisible(false);
            in_Sewa.dateChosser_Sewa_TanggalKembali2.setEnabled(false);
            in_Sewa.tf_Sewa_UangSewa.setEnabled(false);
            in_Sewa.button_Sewa_Ok.setEnabled(false);

            String reportSource = "./reports/NotaSewa.jasper";
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("userStaff", label_Karyawan.getText());
            params.put("tanggalNota", label_dateSewa.getText());
            params.put("noFaktur", label_NoFaktur.getText());
            params.put("namaPenyewa", label_NilaiNamaPenyewa.getText());
            params.put("alamatPenyewa", label_NilaiAlamatPenyewa.getText());
            params.put("noTelpPenyewa", label_NilaiNoTelpPenyewa.getText());
            params.put("merkMobil", label_NilaiMerkMobil.getText());
            params.put("noPolisi", label_NilaiNoPolisi.getText());
            params.put("warnaKendaraan", label_NilaiWarnaKend.getText());
            params.put("tipeKendaraan", label_NilaiTipeKend.getText());
            params.put("spesifikasiKend", label_NilaiSpesifiaksiKend.getText());
            params.put("tglSewa", label_NilaiTglSewa.getText());
            params.put("tglKembali", label_NilaiTglKemb.getText());
            params.put("uangSewa", label_NilaiUangSewa.getText());

            this.setVisible(false);
            JasperPrint jasperPrint = JasperFillManager.fillReport("./reports/NotaSewa.jasper", params);
            JasperViewer.viewReport(jasperPrint, false);
        } catch (JRException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        }
    }//GEN-LAST:event_cetakButtonActionPerformed

    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//
//            public void run() {
//                FormCetakStruk dialog = new FormCetakStruk(new javax.swing.JInternalFrame(), true);
//                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
//
//                    public void windowClosing(java.awt.event.WindowEvent e) {
//                        System.exit(0);
//                    }
//                });
//                dialog.setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cetakButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JLabel label_AlamatPenyewa;
    private javax.swing.JLabel label_Karyawan;
    private javax.swing.JLabel label_MerkMobil;
    private javax.swing.JLabel label_NilaiAlamatPenyewa;
    private javax.swing.JLabel label_NilaiMerkMobil;
    private javax.swing.JLabel label_NilaiNamaPenyewa;
    private javax.swing.JLabel label_NilaiNoPolisi;
    private javax.swing.JLabel label_NilaiNoTelpPenyewa;
    private javax.swing.JLabel label_NilaiSpesifiaksiKend;
    private javax.swing.JLabel label_NilaiTglKemb;
    private javax.swing.JLabel label_NilaiTglSewa;
    private javax.swing.JLabel label_NilaiTipeKend;
    private javax.swing.JLabel label_NilaiUangSewa;
    private javax.swing.JLabel label_NilaiWarnaKend;
    private javax.swing.JLabel label_NoFaktur;
    private javax.swing.JLabel label_NoPolisi;
    private javax.swing.JLabel label_NoTelpPenyewa;
    private javax.swing.JLabel label_SpesifikasiKendaraan;
    private javax.swing.JLabel label_TanggalKembali;
    private javax.swing.JLabel label_TanggalSewa;
    private javax.swing.JLabel label_TipeKendaraan;
    private javax.swing.JLabel label_TitleCorp;
    private javax.swing.JLabel label_UangSewa;
    private javax.swing.JLabel label_WarnaKendaraan;
    private javax.swing.JLabel label_dateSewa;
    private javax.swing.JLabel label_namaPenyewa;
    // End of variables declaration//GEN-END:variables
}
